package com.uex.dev.manage.admin.controller;

import com.google.common.base.Preconditions;
import com.uex.dev.manage.admin.po.UserPO;
import com.uex.dev.manage.admin.service.IServiceCodeService;
import com.uex.dev.manage.admin.service.IUserService;
import com.uex.dev.manage.admin.vo.wx.BindResp;
import com.uex.dev.manage.common.base.ModelResult;
import io.micrometer.common.util.StringUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

/**
 * @author lzs
 * @create 2024/02/27
 * @description
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@Tag(name = "小程序绑定")
@RequestMapping("/wxapp")
@RestController
public class WxBindController {

    @Resource
    private IUserService userService;

    @Resource
    private IServiceCodeService serviceCodeService;

    @Operation(description = "获取WXID绑定关系")
    @GetMapping("/bind")
    public ModelResult<BindResp> getBind(HttpServletRequest request) {
        return new ModelResult<>(userService.getBind(request));
    }

    @Operation(description = "内部用户绑定WXID")
    @PostMapping("/userbind")
    public ModelResult<BindResp> userBind(@RequestBody UserPO userBindReq) {
        Preconditions.checkArgument(StringUtils.isNotBlank(userBindReq.getUserAccount()), "用户账号不能为空");
        Preconditions.checkArgument(StringUtils.isNotBlank(userBindReq.getUserPasswd()), "用户密码不能空");
        return new ModelResult<>(userService.userBind(userBindReq));
    }

    @Operation(description = "访客绑定服务码")
    @GetMapping("/guestbind")
    public ModelResult<Integer> guestBind(@RequestParam String serviceCode) {
        return new ModelResult<>(serviceCodeService.guestBind(serviceCode));
    }
}

